package newspapers.autopublishing;

public class AutoGen {

    public static String getString() {

        int n = (int) (Math.random() * 20) + 4;

        char[] text = new char[n];

        int c = 'A';

        int r1 = 0;
        for (int i = 0; i < n; i++) {
            r1 = (int) (Math.random() * 3);

            switch(r1) {

            case 0: c = '0' + (int) (Math.random() * 10); break;
            case 1: c = 'a' + (int) (Math.random() * 26); break;
            case 2: c = 'A' + (int) (Math.random() * 26); break;

            }
            text[i] = (char) c;
        }

        return new String(text);
    }

    public static String getValue() {

        int n = (int) (Math.random() * 20) + 4;

        char[] text = new char[n];

        int c = 'A';

        int r1 = 0;
        for (int i = 0; i < n; i++)    {
            r1 = (int) (Math.random() * 3);

            switch(r1) {
                case 0: c = '0' + (int) (Math.random() * 10); break;
            }
            text[i] = (char) c;
        }

        return new String(text);
    }

    public static String getNameString(int len, int distribution,
            double std_deviation) {

        int n = 0;
        // constant message length
        if (distribution == 0) {
            n = len;
        }

        // uniform distribution, currently standard
        if (distribution == 1) {

            n = (int) (Math.random() * len * 2);
            if (n == 0) {
                n++;
            }

        }

        char [] text = new char[n];

        int c = 'A';

        int r1 = 0;
        for (int i = 0; i < n; i++) {
            r1 = (int) (Math.random() * 3);

            switch(r1) {
                case 0: c = '0' + (int) (Math.random() * 10); break;
                case 1: c = 'a' + (int) (Math.random() * 26); break;
                case 2: c = 'A' + (int) (Math.random() * 26); break;
            }
            text[i] = (char) c;
        }

        return new String(text);
    }

    public static String getValueString(int len, int distribution,
            double std_deviation) {

        int n = 0;
        // constant message length
        if (distribution == 0) {
            n = len;
        }

        // uniform distribution, currently standard
        if (distribution == 1) {

            n = (int) (Math.random() * len * 2);
            if (n == 0) {
                n++;
            }

        }

        char[] text = new char[n];

        int c = 'A';

//        int r1=0; //Bea removes this because it wasn't being used
        for (int i = 0; i < n; i++)    {
            c = '0' + (int) (Math.random() * 10);

            text[i] = (char) c;
        }

        return new String(text);
    }


    // change the message rate and delay to the real y parameter
    // R=
    public static double transferRate(int rate, int delay) {
        double y = 0.0;

        y = (-Math.log10(0.5) * rate * delay) / (60 * 1000);

        return y;
    }

    // get the next publish time which has the time interval follows an
    //exponential distribution, returns in seconds
    public static double getNextPublishTimeExp(int rate, double uniRnd)    {
        double mPerSecond = ((double) rate) / 60;
        return (-1.0 / mPerSecond) * Math.log(uniRnd);
    }

    // get the next publish time which is uniform to the rate,
    //returns in seconds
    public static double getNextPublishTimeUni(int rate) {
        return 60.0 / ((double) rate);
    }

}
